//char3是否由char1,char2交错组成
public class IsCross {
}
class IsCrossSolution {
    public boolean isInterleave(String s1, String s2, String s3) {
        char[] char1 = s1.toCharArray();
        char[] char2 = s2.toCharArray();
        char[] char3 = s3.toCharArray();
        int n1 = char1.length;
        int n2 = char2.length;
        int n3 = char3.length;
        if(n1+n2!=n3)return false;
        boolean[][] dp = new boolean[n1+1][n2+1];
        dp[0][0] = true;
        for(int i=0;i<n1;i++){
            if(char1[i]==char3[i])dp[i+1][0]=true;
            else break;
        }
        for(int i=0;i<n2;i++){
            if(char2[i]==char3[i])dp[0][i+1]=true;
            else break;
        }
        for(int i=1;i<n1+1;i++){
            for(int j=1;j<n2+1;j++){
                if(char3[i+j-1]==char1[i-1])dp[i][j] |= dp[i-1][j];
                if(char3[i+j-1]==char2[j-1])dp[i][j] |= dp[i][j-1];
            }
        }
        return dp[n1][n2];
    }
}